#include "Cons.h"
#include "EmptyList.h"
#include "RT.h"
namespace clojure_lang {
Cons::Cons(IPersistentMap *meta, CjObject *first, ISeq *more) : ASeq(meta)
{
    _first = first;
    _more = more;
}

Cons::Cons(CjObject *first, ISeq *more)
{
    _first = first;
    _more = more;
}

CjObject *Cons::withMeta(IPersistentMap *meta)
{
    return (meta == _meta ?
                this :
                (new Cons(meta, _first, _more))->dynamicCast<CjObject>());

}


CjObject *Cons::first()
{
    return _first;
}

ISeq *Cons::next()
{
    return more()->seq();
}

ISeq *Cons::more()
{
    if (_more == NULL)
        return (new EmptyList())->dynamicCast<ISeq>();
    return _more;
}

int Cons::count()
{
    return 1 + RT::count(dynamic_cast<CjObject *>(_more));
}


}
